//#####################################################################
//																	
//		FILE:			fileMgr.h	< Ver 0.01 >
//
//		DESC:			FileManager
//
//		CREATED BY:		HJ
//
//		HISTORY:		2005_10_13
//
//		LAST UPDATE:	2005_10_13
//
//#####################################################################
#pragma once

#define		_STLP_USE_NEWALLOC
/*---------------------------------------------
					Include
---------------------------------------------*/
#include <Windows.h>
#include <vector>
#include <stdio.h>
#include <tchar.h>

using namespace std;
/*---------------------------------------------
					Define
---------------------------------------------*/
//		Execpt Option		//
#define		HJFO_EXCEPTFOLDER		0x0001	// Execption Folder
#define		HJFO_EXCEPTEXT			0x0002	// Execption Ext

//		NumOfFile Option		//
#define		HJFO_ONLYCURFOLDER		0x0011
#define		HJFO_LOWFOLDER			0x0012
#define		HJFO_ONLYCURFNAME		0x0013
#define		HJFO_LOWFNAME			0x0014

/*---------------------------------------------
					Enum
---------------------------------------------*/
enum	CreateFolder_ErrorMsg
{
    ERR_NOTFOUND_DRIVE = 2,
	ERR_NOTFOUND_PARENT,
	ERR_DIFFERENT_DRIVE,	//With Parent
	ERR_INPUT_DRIVENAME,	//With first case
	ERR_NOTSECONDCASE,		//With first case
	ERR_INPUT_FOLDERNAME,	
	ERR_NOTPUTONLIST,
};

/*---------------------------------------------
					Struct
---------------------------------------------*/
struct FOLDERINFO
{
	TCHAR	szName[_MAX_FNAME];
	TCHAR	szPath[MAX_PATH];
	TCHAR	szTopName[_MAX_FNAME];

	int		nIdenticalNameID;

	FOLDERINFO* pParent;
	FOLDERINFO* pChild;

	FOLDERINFO* pNext;
	FOLDERINFO* pPrev;

	FOLDERINFO() : nIdenticalNameID(0) , pParent(NULL) , pChild(NULL) , pNext(NULL) , pPrev(NULL)
	{
		memset( szName , 0 , sizeof(TCHAR) * _MAX_FNAME );
		memset( szPath , 0 , sizeof(TCHAR) * _MAX_FNAME );
		memset( szTopName , 0 , sizeof(TCHAR) * _MAX_FNAME );
	}
};

struct FILEINFO
{
	WIN32_FIND_DATA		fd;
	TCHAR				szFilePath[MAX_PATH];

	FILEINFO()
	{
		memset( &fd , 0 , sizeof(WIN32_FIND_DATA) );
		memset( szFilePath , 0 , sizeof( TCHAR ) * MAX_PATH );
	}
};

struct FILEINFOMGR
{
	vector<FILEINFO>			vtFData;
	vector<FILEINFO>::iterator	iter;
	int							nNumOfFile;

	FILEINFOMGR() : nNumOfFile(0) , iter(NULL)
	{
		vtFData.clear();
	}
};

/*---------------------------------------------
					CLASS
---------------------------------------------*/
class CFileMng
{
private:
	vector<TCHAR*>					m_vtExecptFolderList;
	vector<TCHAR*>					m_vtExecptExtList;

	vector<TCHAR*>::iterator		m_itTCHAR;

	vector<FOLDERINFO*>				m_vtCreateFolderList;
	vector<FOLDERINFO*>::iterator	m_itFolderInfo;

public:

	BOOL	CleanDirectory( const TCHAR* szpPath , const TCHAR* szpDelExp , const DWORD dwOption = 0 );

	//		Execpt Funtion		//
	inline	VOID	AddExecptionFolder( TCHAR* szFolderName )	{ m_vtExecptFolderList.push_back(szFolderName); }
	inline	VOID	AddExecptionFileExt( TCHAR* szpExtName )	{ m_vtExecptExtList.push_back(szpExtName);		}
	inline	VOID	ClearExecptionFolderList()					{ m_vtExecptFolderList.clear();					}
	inline	VOID	ClearExecptionExxList()						{ m_vtExecptExtList.clear();					}

    //		Create Folder Funtion		//
	BOOL	AddFolder( const TCHAR* szpFolderName , const TCHAR* szpParentFolderName = NULL , const TCHAR* szDrive = NULL );
	BOOL	CreateFolder();

	INT		NumOfFileCount( TCHAR* szpPath , DWORD dwOption );
	TCHAR*	DumpFileName( TCHAR* szpPath , TCHAR* szpFileName );

	//		Search File		//
	BOOL	SearchFile( TCHAR* szFilePath );

	//		Find File		//
	BOOL	GetFilesFromDir( FILEINFOMGR& FInfo , TCHAR* szFindDir , TCHAR* szFindExt = NULL , bool bDown = false );

private:

	inline	BOOL	ExecptionFolder( TCHAR* szpCurFolder , TCHAR* szpExecptFolder ) {
        if( !_tcscmp( szpCurFolder , szpExecptFolder ) )
		{
			return TRUE;
		}
		return FALSE;
	}

	inline	BOOL	ExecptionFileExt( TCHAR* szpCurExt , TCHAR* szpExeptExt ) {
		if( !_tcscmp(szpCurExt , szpExeptExt ) )
		{
			return TRUE;
		}
		return FALSE;
	}

	VOID	LoopCreateFolder( FOLDERINFO* pFolder );
	VOID	ReleaseFileMng();
	VOID	ReleaseFolder();

public:
	CFileMng(void) : m_itTCHAR(NULL) , m_itFolderInfo(NULL) {
		m_vtExecptFolderList.clear();
		m_vtExecptExtList.clear();
		m_vtCreateFolderList.clear();
	}

	~CFileMng(void) { ReleaseFileMng(); };
};

























